#ifndef FOLDERONLYPROXYMODEL_H
#define FOLDERONLYPROXYMODEL_H
#include <QSortFilterProxyModel>
#include <QFileSystemModel>
#include <QFileInfo>

/**
 * 代理模型，只显示文件夹
 */
class FolderOnlyProxyModel : public QSortFilterProxyModel {
public:
    explicit FolderOnlyProxyModel(QObject *parent = nullptr) : QSortFilterProxyModel(parent) {}

protected:
    bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override {
        QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
        if (!index.isValid()) return false;

        QFileSystemModel *fileModel = qobject_cast<QFileSystemModel*>(sourceModel());
        if (fileModel) {
            QFileInfo fileInfo = fileModel->fileInfo(index);
            return fileInfo.isDir();
        }
        return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
    }
};
#endif // FOLDERONLYPROXYMODEL_H